<?php
/*
 * author:tomshao
 * 用途：
 * */
$link = mysqli_connect(
		'115.28.15.160',   /* The host to connect to 连接MySQL地址 */
		'chinalaohu',          /* The user to connect as 连接MySQL用户名 */
		'j2jsdIwEi8Jdh21H',           /* The password to use 连接MySQL密码 */
		'chinalaohu_lh');    /* The default database to query 连接数据库名称  */
mysqli_query($link, "set names utf8");
if(!$link)
{
	
	$order_str="{\"success\":\"0\",\"errCode\":\"-1\"}";
	
	
	echo $order_str;
	die;
}
else
{	

$uuid=$_REQUEST["uuid"];  //用户的UUID
$platform=$_REQUEST["platform"];;  //用户的PLATFORM  0:安卓  1:苹果

$x_sql="select *  from user_base where muuid='".$uuid."'";
$result = mysqli_query($link, $x_sql);

	$uid="";
	if($result)
	{
	if( $row = mysqli_fetch_assoc($result) )
	
	{
		
		$uid=$row["uid"];
	}
	else
	{
		
			$order_str="{\"success\":\"0\",\"errCode\":\"0\"}";
		
		
		echo $order_str;
		die;
	}	
}


$x_sql="select *  from auction_userwonpaid where  pay_status=0  and  uid='".$uid."'";
//	$x_sql="select *  from auction_userwonpaid where  pay_status=0   and  uid=10107";
	
$result = mysqli_query($link, $x_sql);
$order_str="";
if($result)
while( $row = mysqli_fetch_assoc($result) )
{
	
$temp_order_info="";
	


$xx_sql="select a.*,c.img_waterfall from  auction_userwon a   left outer join   auction b on a.aid=b.aid  left outer join  auction_gallery c on b.agid =c.agid   where a.paidID='".$row["paidID"]."'";
//echo 	$xx_sql;
$xx_result = mysqli_query($link, $xx_sql);
	$temp_aid="";
	$temp_goods_count=0;

	 
	$temp_goods_info="";
//	echo $xx_sql;
	while( $xx_row = mysqli_fetch_assoc($xx_result) )
	{
		if($temp_aid=="")
			$temp_aid=$xx_row["aid"];
	   	$temp_goods_count=$temp_goods_count+1;
		
		
		$temp_icon_url="";
		if($platform=="0")
			//0:安卓
		{
			$temp_icon_url="http://img1.chinalaohu.com".$xx_row["img_waterfall"];
			$temp_icon_url=str_replace("/upload/","/upload/adio/",$temp_icon_url);
		}
		elseif($platform=="1")
			//1:苹果
		{
			
			$temp_icon_url="http://img1.chinalaohu.com".$xx_row["img_waterfall"];
			$temp_icon_url=str_replace("/upload/","/upload/ios/",$temp_icon_url);
		}
	
		$temp_goods_info2="{\"aid\":\"".$xx_row["aid"]."\",\"auctionCode\":\"".$xx_row["acode"]."\",\"iconUrl\":\"".$temp_icon_url."\",\"name\":\"".str_replace("\"","\\\"",$xx_row["auction"])."\",\"dealTime\":\"".""."\",\"price\":\"".$xx_row["bid_amount"]."\"}";
		
		if($temp_goods_info=="")
		{
			$temp_goods_info=$temp_goods_info2;
		}
		else
			$temp_goods_info=$temp_goods_info.",".$temp_goods_info2;
	
	}
	
// echo  "temp_goods_info=".$temp_goods_info;
if($temp_aid!="")
{	
	$temp_order_info=$temp_order_info."{\"aid\":\"".$temp_aid."\"";
	$temp_order_info=$temp_order_info.",\"addressId\":\"".$row["ship_addrid"]."\"";
	$temp_order_info=$temp_order_info.",\"payType\":\"".$row["payment"]."\"";
	$temp_order_info=$temp_order_info.",\"orderId\":\"".$row["paidID"]."\"";
	$temp_order_info=$temp_order_info.",\"tnId\":\"".$row["tnId"]."\"";
	$temp_order_info=$temp_order_info.",\"orderTime\":\"".$row["createtime"]."\"";
	$temp_order_info=$temp_order_info.",\"address\":\"".$row["ship_area"].$row["ship_addr"]."\"";
	$temp_order_info=$temp_order_info.",\"despatchType\":\"".$row["shipment"]."\"";
	$temp_order_info=$temp_order_info.",\"pay\":\"".$row["final_amount"]."\"";
	$temp_order_info=$temp_order_info.",\"goodsCount\":\"".$temp_goods_count."\"";
	$temp_order_info=$temp_order_info.",\"remarks\":\"".$row["remark"]."\"";
	$temp_order_info=$temp_order_info.",\"list\":[".$temp_goods_info."]}";
//	echo $temp_order_info;
	
	if($order_str=="")
	{
		$order_str=$temp_order_info;
	}
	else
		$order_str=$order_str.",".$temp_order_info;

}
	
}

$order_str="{"."\"success\":\"1\",\"myOrder\":[".$order_str."]}";
echo $order_str;
}
?>